package com.health.trans.processor.listener;

import com.health.trans.kit.ThreadMonitor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;

/**
 * @author nqlz
 */
@Slf4j
@NoArgsConstructor
public class JobEndListener extends JobExecutionListenerSupport {

    private JobExecution jobExecution;

    public String getTime() {
        return  ThreadMonitor.getTime(jobExecution.getStartTime(), jobExecution.getEndTime());
    }

    @Override
    public void afterJob(JobExecution jobExecution) {
        if (jobExecution.getStatus() == BatchStatus.COMPLETED) {
            log.info("监控到任务已完成。console batch job complete!");
        }
    }

    @Override
    public void beforeJob(JobExecution jobExecution) {
        this.jobExecution = jobExecution;
        log.info("任务开始。。job before " + jobExecution.getJobParameters());
    }
}
